# encoding: utf-8
""" 
@version: v1.0 
@author: autumner 
@license: Apache Licence  
@contact: 18322313385@163.com 
@site:  https://gitee.com/autumner/pythoncookbook
@software: PyCharm 
@file: net_memoryviews_server.py 
@time: 2019/7/31 上午10:36
@note:
利用函数memoryviews来发送和接受大数组
"""

def send_from(arr, dest):
    '发送大数组函数'
    view = memoryview(arr).cast('B')
    while len(view):
        nsent = dest.send(view)
        view = view[nsent:]


from socket import *

# 创建socket服务
s = socket(AF_INET, SOCK_STREAM)
s.bind(('', 35000))
s.listen(2)
sock, addr = s.accept()

import numpy

# 发送大数组
arr = numpy.arange(0.0, 50000000.0)
send_from(arr, sock)
# 关闭socket
s.close()